package tt.dz.appserver.service.avro.test;

import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;

import org.apache.avro.ipc.NettyTransceiver;
import org.apache.avro.ipc.specific.SpecificRequestor;

public class Client {

	private String host = null;
	private int port = 0;
	private static MessageProtocol proxy;

	public Client(String host, int port, int size, int count) {
		this.host = host;
		this.port = port;
	}

	public long sendMessage() throws Exception {
		
		NettyTransceiver client = new NettyTransceiver(new InetSocketAddress(host, port));
		proxy = SpecificRequestor.getClient(MessageProtocol.class, client);
		long start = System.currentTimeMillis();
		long end = System.currentTimeMillis();
		return end - start;
	}


	public static void main(String[] args){
		String host = "192.168.5.209";
		int port = 9511;
		int size = 1;
		int count = 2;
		try {
			System.out.println(new Client(host, port, size, count).sendMessage());
		} catch (Exception e1) {
			e1.printStackTrace();
		}
		
		while (true) {
			try {
				System.out.println("ol...........");
				Message message = new Message();
				message.setName("哈哈哈哈");
				message.setType(1);;
				message.setPrice(999.99);
				message.setValid(true);
				message.setContent(ByteBuffer.wrap("Hello".getBytes()));
				List<CharSequence> list = new ArrayList<CharSequence>();
				list.add("test");
				list.add("hello");
				list.add("world");
				message.setTags(list);
				System.out.println(proxy.test(message, 200, "可以有"));
				System.out.println(proxy.sendMessage(message));
			} catch (Exception e) {
				e.printStackTrace();
			}
			break;
		}
	}
}
